package com.bawei.admin.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bawei.admin.util.OSSFileUtil;
import com.bawei.admin.vo.CheckDoctorVo;
import com.bawei.admin.vo.CheckQueryVo;
import com.bawei.common.utils.JwtUtil;
import com.bawei.common.vo.DoctorVo;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bawei.admin.entity.AdminEntity;
import com.bawei.admin.service.AdminService;
import com.bawei.common.utils.PageUtils;
import com.bawei.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author lty
 * @email 1282253935@qq.com
 * @date 2021-12-09 16:22:37
 */
@RestController
@RequestMapping("admin/admin")
public class AdminController {



    @Autowired
    private AdminService adminService;

    @Autowired
    private JwtUtil jwtUtil;

    //添加医师
    @PostMapping("addDoctor")
    public R addDoctor(@RequestBody DoctorVo doctorVo){
        adminService.addDoctor(doctorVo);
        return R.ok();
    }


    //上传图片
    @RequestMapping("/oss")
    public String oss(MultipartFile file) throws IOException {
        String s = OSSFileUtil.uploadFile(file);
        return s;
    }

    //查看医生列表
    @GetMapping("/listDoctorStatus")
    public R listDoctorStatus(@RequestParam Map<String, Object> params) {
        return adminService.listDoctorStatus(params);
    }


    //返回单独的医生
    @GetMapping("/listDoctorMsgByDoctorId/{doctorId}")
    public R listDoctorMsgByDoctorId(@PathVariable("doctorId") Integer doctorId){

        return adminService.listDoctorMsgByDoctorId(doctorId);
    }


    //管理员登陆

    @PostMapping("/login")
    public R login(@RequestBody AdminEntity adminEntity) {
        if (adminEntity != null) {
            AdminEntity admin = adminService.getAdminByAdminName(adminEntity.getAdminName());
            if (adminEntity.getAdminPwd().equals(admin.getAdminPwd())) {
                String token = jwtUtil.createJWT(admin.getAdminName(), admin.getAdminName(), "admin");
                return R.ok().put("admin", admin).put("token", token);
            }
        }
//        AdminEntity one = adminService.getOne(new QueryWrapper<AdminEntity>(adminEntity));
        return R.error();
    }

    //审核医生
    @PostMapping("/checkedDoctorList")
    public R checkedDoctorList(@RequestBody CheckQueryVo checkQueryVo){
        PageUtils page = adminService.checkedDoctorList(checkQueryVo);
        return R.ok().put("page", page);
    }

    //修改医生
    @PostMapping("/checkDoctorStatus")
    public R checkDoctorStatus(@RequestBody CheckDoctorVo checkDoctorVo ){
        return adminService.checkDoctorStatus(checkDoctorVo);
    }


    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = adminService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @PostMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        AdminEntity admin = adminService.getById(id);

        return R.ok().put("admin", admin);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody AdminEntity admin) {
        adminService.save(admin);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody AdminEntity admin) {
        adminService.updateById(admin);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        adminService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }




}
